package Solutions


func findLongestSubarray(array []string) []string {
	preSum := make([]int, len(array)+1)
	sum := 0
	for i, v := range array {
		if v[0] <= '9' {
			sum += 1
		} else {
			sum -= 1
		}
		preSum[i+1] = sum
	}
	max := -1
	ansR := -1
	ansL := -1
	var mp1 = map[int]int{}
	var mp2 = map[int]int{}
	for i := 0; i < len(preSum); i++ {
		if _, ok := mp1[preSum[i]]; !ok {
			mp1[preSum[i]] = i
		}
		mp2[preSum[i]] = i
	}
	for k, v := range mp1 {
		if v1, ok := mp2[k]; ok {
			if v1-v > max {
                max = v1 - v
                    ansL = v
				    ansR = v1
			}else if v1-v==max{
                if v<ansL{
                    ansL=v
                    ansR=v1
                }
            }
		}
	}
	if ansL != -1 {
		return array[ansL:ansR]
	} else {
		return []string{}
	}
}